package cn.tedu.course.carousel.controller;


import cn.tedu.course.base.response.JsonResult;
import cn.tedu.course.carousel.pojo.dto.CarouselQuery;
import cn.tedu.course.carousel.pojo.dto.CarouselSaveParam;
import cn.tedu.course.carousel.pojo.vo.CarouselVO;
import cn.tedu.course.carousel.service.CarouselService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name="轮播图模块")
@Slf4j
@RestController
@RequestMapping("/v1/carousel")
public class CarouselController {
    @Autowired
    CarouselService carouselService;

    @Operation(summary = "查询轮播图")
    @ApiOperationSupport(order = 10)
    @GetMapping("select")
    public JsonResult selectCarousel(CarouselQuery carouselQuery){
        log.debug("查询轮播图:carousel={}",carouselQuery);
        List<CarouselVO> list = carouselService.selectCarousel(carouselQuery);
        return JsonResult.ok(list);

    }

    @Operation(summary = "新增轮播图")
    @ApiOperationSupport(order = 20)
    @PostMapping("save")
    public JsonResult saveCarousel(@Validated CarouselSaveParam carouselSaveParam){
        log.debug("保存轮播图:carouselsaveparam={}",carouselSaveParam);
        carouselService.saveCarousel(carouselSaveParam);
        return JsonResult.ok();
    }

    @Operation(summary = "删除轮播图")
    @ApiOperationSupport(order = 30)
    @PostMapping("delete/{carouselId}")
    public JsonResult deleteCarousel(@PathVariable Long carouselId){
        log.debug("删除轮播图:carouselIdId={}",carouselId);
        carouselService.deleteCarousel(carouselId);
        return JsonResult.ok();
    }

}
